package com.ihr360.commons.model.entity;

import com.ihr360.commons.model.IBaseCodeEntity;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Date;


public abstract class BaseCode<T extends Number> extends NumberId<T> implements IBaseCodeEntity {
    private static final long serialVersionUID = 5728157880502841506L;

    protected String code;

    protected String name;

    protected String engName;

    protected Date effectiveAt;
    protected Date invalidAt;
    protected Date createdAt;
    protected Date updatedAt;

    public BaseCode() {
    }

    public BaseCode(T id) {
        this.id = id;
    }

    public Date getCreatedAt() {
        return this.createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getUpdatedAt() {
        return this.updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public boolean hasExtPros() {
        Field[] fields = this.getClass().getDeclaredFields();

        for (int i = 0; i < fields.length; ++i) {
            if (!Modifier.isFinal(fields[i].getModifiers()) && !Modifier.isStatic(fields[i].getModifiers())) {
                return true;
            }
        }

        return false;
    }
    @Override
    public String getCode() {
        return this.code;
    }
    @Override
    public void setCode(String code) {
        this.code = code;
    }
    @Override
    public String getName() {
        return this.name;
    }
    @Override
    public void setName(String name) {
        this.name = name;
    }
    @Override
    public String getEngName() {
        return this.engName;
    }
    @Override
    public void setEngName(String engName) {
        this.engName = engName;
    }
    @Override
    public Date getEffectiveAt() {
        return this.effectiveAt;
    }
    @Override
    public void setEffectiveAt(Date effectiveAt) {
        this.effectiveAt = effectiveAt;
    }
    @Override
    public Date getInvalidAt() {
        return this.invalidAt;
    }
    @Override
    public void setInvalidAt(Date invalidAt) {
        this.invalidAt = invalidAt;
    }

    @Override
    public int compareTo(Object arg0) {
        BaseCode other = (BaseCode)arg0;
        return this.getCode().compareTo(other.getCode());
    }

    @Override
    public String toString() {
        return "BaseCode{" +
                "code='" + code + '\'' +
                ", name='" + name + '\'' +
                ", engName='" + engName + '\'' +
                ", effectiveAt=" + effectiveAt +
                ", invalidAt=" + invalidAt +
                ", createdAt=" + createdAt +
                ", updatedAt=" + updatedAt +
                '}';
    }
}